package com.fc.design.strategy;

/**
 * <p> Author：lidongxu </p>
 * <p> Title：</p>
 * <p> Description：</p>
 * <p> Create Time：2020-04-07 14:44 </p>
 */
public class StrategyTest {
    public static void main(String[] args) {
        Context c = new Context();
        Strategy s = new ConcreteStrategyA();
        c.setStrategy(s);
        c.strategyMethod();
        System.out.println("-----------------");
        s = new ConcreteStrategyB();
        c.setStrategy(s);
        c.strategyMethod();
    }
}

class Context {
    private Strategy strategy;

    public void setStrategy(Strategy strategy) {
        this.strategy = strategy;
    }

    public Strategy getStrategy() {
        return strategy;
    }

    public void strategyMethod() {
        strategy.StrategyMethod();
    }
}

interface Strategy {
    public void StrategyMethod();
}

class ConcreteStrategyA implements Strategy {
    public void StrategyMethod() {
        System.out.println("策略A");
    }
}

class ConcreteStrategyB implements Strategy {
    public void StrategyMethod() {
        System.out.println("策略B");
    }
}